package cn.laixueit.dao;

import cn.laixueit.domain.User;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 注解实现crud
 */
public interface IUserDao {

    @Select("select * from user where id =#{id}")
    @ResultMap(value = {"userMap"})
    public User findOne(Integer id);

    @Select(value = "select * from user")
    @Results(
            id = "userMap",
            value = {
                    @Result(id = true, column = "id", property = "userId"),
                    @Result(column = "username", property = "userName"),
                    @Result(column = "address", property = "userAddress"),
                    @Result(column = "sex", property = "userSex"),
                    @Result(column = "birthday", property = "userBirthday")
            }
    )
    public List<User> findAll();



    @Select("select * from user where username like '%${value}%'")
    @ResultMap(value = {"userMap"})
    public List<User> findLikeName(String username);

    @Select("select count(1) from user")
    public Integer count();


}
